<?php
class settingModel extends RPHP_Model
{

    protected $_auth = null;

    //检查权限
    public function checkPriv($pv, $return = true)
    {
        $auth = $this->auth->CheckPriv($pv, $return);
        if ($return) {
            $this->_auth = $auth;
        }

        return $auth;
    }

    // 获取设置
    public function getSetting()
    {
        $sql     = "SELECT `setting` FROM {$this->_prefix['primary']}setting ORDER BY `setting_id` DESC LIMIT 1";
        $setting = $this->db->getone($sql);
        if ($setting != "") {
            return json_decode($setting, true);
        }

    }

    // 保存设置
    public function saveSetting($da)
    {
        unset($da['act']);
        if($da['coupon_money']) {

            foreach ($da['coupon_money'] as $k => $v) {
                $da['coupon_money'][$k] = intval($v);

            }

        }

        if($da['coupon_money'])
        $setting = json_encode($da);

        $sql = "UPDATE {$this->_prefix['primary']}setting SET
        `setting`='" . $setting . "',
        `last_aid`=" . $this->_auth['aid'] . ",
        `last_edit`=" . $_SERVER['REQUEST_TIME'];
        $rcs = $this->sql($sql);
        if ($rcs > 0) {
            $code = 200;
        } else {
            $code = 403;
        }

        return $code;
    }

}
